package com.netrust.cmsx.entity.module.cms;

import static javax.persistence.GenerationType.IDENTITY;

import java.sql.Timestamp;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.netrust.cmsx.entity.module.site.SiteCategories;
import com.netrust.cmsx.entity.module.sys.Attach;

/**
 * 文章表
 * 
 * @author Administrator
 *
 */
@Entity
@Table(name = "t_article")
public class Article {
	private Integer id;

	private Integer acId;// 文章内容的外键ID

	private String title;// 标题

	private String subTitle;// 副标题

	private String summary;// 摘要

	private String coverUrl;// 封面图片路径

	private Integer status;// -1:草稿; 0:未审核; 1:审核通过; 2:审核中; 3:被退回;4:删除的

	private Integer isOuter;// 是否外链(true为外链，false不是外链)

	private String linkPath;// 外链路径

	private Integer isTop;// 是否置顶(true为置顶，false不是置顶)，置顶后仍按place排序

	private Integer isComment;// 是否允许评论该文章。默认true允许，false不允许

	private Integer place;// 排序

	private Integer createUser;// 创建人。保存用户的ID

	private String author;// 作者

	private Timestamp createTime;// 创建时间

	private Integer viewNums;// 浏览次数

	private Timestamp pubTime;// 发布时间

	private ArticleContents articleContents;
	
	@JsonIgnore
	private List<Attach> attachs;

	@JsonIgnore
	private List<AttachArticle> attachArticles;

	@JsonIgnore
	private List<SiteCategories> siteCategories;

	@JsonIgnore
	private List<ArticleComment> articleCommentList;

	private Timestamp validStartTime;// 文章开始有效时间

	private Timestamp validEndTime;// 文章结束有效时间

	private Integer pubNow;// 是否立即发布

	public Article() {
		super();
	}

	public Article(Integer id) {
		super();
		this.id = id;
	}

	public Article(Integer id, Integer acId, String title, String subTitle, String summary, String coverUrl,
			Integer status, Integer isOuter, String linkPath, Integer isTop, Integer isComment, Integer place,
			Integer createUser, String author, Timestamp createTime, Integer viewNums, Timestamp pubTime,
			Timestamp validStartTime, Timestamp validEndTime, Integer pubNow, ArticleContents articleContents,
			List<Attach> attachs, List<AttachArticle> attachArticles, List<SiteCategories> siteCategories) {
		super();
		this.id = id;
		this.acId = acId;
		this.title = title;
		this.subTitle = subTitle;
		this.summary = summary;
		this.coverUrl = coverUrl;
		this.status = status;
		this.isOuter = isOuter;
		this.linkPath = linkPath;
		this.isTop = isTop;
		this.isComment = isComment;
		this.place = place;
		this.createUser = createUser;
		this.author = author;
		this.createTime = createTime;
		this.viewNums = viewNums;
		this.pubTime = pubTime;
		this.validStartTime = validStartTime;
		this.validEndTime = validEndTime;
		this.pubNow = pubNow;
		this.articleContents = articleContents;
		this.attachs = attachs;
		this.attachArticles = attachArticles;
		this.siteCategories = siteCategories;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "a_id", unique = true, nullable = false)
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "a_ac_id",insertable=false,updatable=false)
	public Integer getAcId() {
		return acId;
	}

	public void setAcId(Integer acId) {
		this.acId = acId;
	}

	@Column(name = "a_title")
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "a_sub_title")
	public String getSubTitle() {
		return subTitle;
	}

	public void setSubTitle(String subTitle) {
		this.subTitle = subTitle;
	}

	@Column(name = "a_summary")
	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	@Column(name = "a_cover_url")
	public String getCoverUrl() {
		return coverUrl;
	}

	public void setCoverUrl(String coverUrl) {
		this.coverUrl = coverUrl;
	}

	@Column(name = "a_status")
	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	@Column(name = "a_is_outer")
	public Integer getIsOuter() {
		return isOuter;
	}

	public void setIsOuter(Integer isOuter) {
		this.isOuter = isOuter;
	}

	@Column(name = "a_link_path")
	public String getLinkPath() {
		return linkPath;
	}

	public void setLinkPath(String linkPath) {
		this.linkPath = linkPath;
	}

	@Column(name = "a_is_top")
	public Integer getIsTop() {
		return isTop;
	}

	public void setIsTop(Integer isTop) {
		this.isTop = isTop;
	}

	@Column(name = "a_is_comment")
	public Integer getIsComment() {
		return isComment;
	}

	public void setIsComment(Integer isComment) {
		this.isComment = isComment;
	}

	@Column(name = "a_place")
	public Integer getPlace() {
		return place;
	}

	public void setPlace(Integer place) {
		this.place = place;
	}

	@Column(name = "a_create_user")
	public Integer getCreateUser() {
		return createUser;
	}

	public void setCreateUser(Integer createUser) {
		this.createUser = createUser;
	}

	@Column(name = "a_author")
	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	@Column(name = "a_create_time")
	public Timestamp getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Timestamp createTime) {
		this.createTime = createTime;
	}

	@Column(name = "a_view_nums")
	public Integer getViewNums() {
		return viewNums;
	}

	public void setViewNums(Integer viewNums) {
		this.viewNums = viewNums;
	}

	@Column(name = "a_pub_time")
	public Timestamp getPubTime() {
		return pubTime;
	}

	public void setPubTime(Timestamp pubTime) {
		this.pubTime = pubTime;
	}

	@Column(name = "a_valid_start_time")
	public Timestamp getValidStartTime() {
		return validStartTime;
	}

	public void setValidStartTime(Timestamp validStartTime) {
		this.validStartTime = validStartTime;
	}

	@Column(name = "a_valid_end_time")
	public Timestamp getValidEndTime() {
		return validEndTime;
	}

	public void setValidEndTime(Timestamp validEndTime) {
		this.validEndTime = validEndTime;
	}

	@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinColumn(name = "a_ac_id")
	public ArticleContents getArticleContents() {
		return articleContents;
	}

	public void setArticleContents(ArticleContents articleContents) {
		this.articleContents = articleContents;
	}

	@JsonIgnore
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "article")
	public List<AttachArticle> getAttachArticles() {
		return attachArticles;
	}

	@JsonIgnore
	public void setAttachArticles(List<AttachArticle> attachArticles) {
		this.attachArticles = attachArticles;
	}

	//@ManyToMany(mappedBy = "articleList") // 这个注解不要去掉,查询文章列表
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) // 多对多外键关联的配置
	@JoinTable(name = "t_article_category", joinColumns = {
			@JoinColumn(name = "a_aid", referencedColumnName = "a_id") }, inverseJoinColumns = {
					@JoinColumn(name = "a_cid", referencedColumnName = "sc_id") })
	public List<SiteCategories> getSiteCategories() {
		return siteCategories;
	}

	public void setSiteCategories(List<SiteCategories> siteCategories) {
		this.siteCategories = siteCategories;
	}

	@Column(name = "a_pubnow")
	public Integer getPubNow() {
		return pubNow;
	}

	public void setPubNow(Integer pubNow) {
		this.pubNow = pubNow;
	}

	@Transient
	public List<Attach> getAttachs() {
		return attachs;
	}

	public void setAttachs(List<Attach> attachs) {
		this.attachs = attachs;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "article")
	public List<ArticleComment> getArticleCommentList() {
		return articleCommentList;
	}

	public void setArticleCommentList(List<ArticleComment> articleCommentList) {
		this.articleCommentList = articleCommentList;
	}

	@Override
	public String toString() {
		return "Article [id=" + id + ", acId=" + acId + ", title=" + title + ", subTitle=" + subTitle + ", summary="
				+ summary + ", coverUrl=" + coverUrl + ", status=" + status + ", isOuter=" + isOuter + ", linkPath="
				+ linkPath + ", isTop=" + isTop + ", isComment=" + isComment + ", place=" + place + ", createUser="
				+ createUser + ", author=" + author + ", createTime=" + createTime + ", viewNums=" + viewNums
				+ ", pubTime=" + pubTime + ", validStartTime=" + validStartTime + ", validEndTime=" + validEndTime
				+ "]";
	}

}